package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 杨林
 * @create 2023-01-28 23:23 星期六
 * description:
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    CustomerService customerService;

    /**
     * 客户列表分页（名称模糊查询）
     * @param page
     * @param rows
     * @param customerName
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> list(Integer page,
                                   Integer rows,
                                   String customerName){

        return customerService.list(page,rows,customerName);
    }


    /**
     * 保存或修改客户
     * @param customer
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveOrUpdate(Customer customer){

        return customerService.saveOrUpdate(customer);
    }

    /**
     * 删除客户
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ServiceVO delete(String ids){
        return customerService.delete(ids);
    }


    /**
     * 客户下拉列表 (可模糊匹配客户名称)
     * @param q
     * @return
     */
    @PostMapping("/getComboboxList")
    public List<Customer> getComboboxList(String q){

        return customerService.getComboboxList(q);
    }

}
